# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=leptosfmt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.33
_ppsha=2dcd20ba8cc15ee0c5eb6970696cff03e5f39b74
pkgrel=1
pkgdesc='A formatter for the leptos view! macro (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://crates.io/crates/leptosfmt/'
msys2_repository_url='https://github.com/bram209/leptosfmt'
msys2_references=(
  'purl: pkg:cargo/leptosfmt'
)
license=('spdx:MIT OR Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("$msys2_repository_url/archive/$pkgver/$_realname-$pkgver.tar.gz"
        "https://github.com/bram209/prettyplease/archive/${_ppsha}/prettyplease-${_ppsha}.tar.gz")
sha256sums=('0a942dcc818815f862570efeab810f450fdae27070489a0cb6a5cef7e04e1f37'
            '95f706cf7c6c5d43c0dc928ee7f2130b57acd4c5da787ccee1180c2a6758205f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  rm -rf "${srcdir}/${_realname}-${pkgver}/prettyplease"
  cp -r "${srcdir}/prettyplease-${_ppsha}" "${srcdir}/${_realname}-${pkgver}/prettyplease"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${srcdir}"
  rm -rf "build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --frozen
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" test \
    --release \
    --frozen
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm644 "LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
}
